from django.db import models
from django.contrib.auth.models import User


# 建立对应的数据库
class UserProfile(models.Model):
    user = models.OneToOneField(User, unique=True)
    # OneToOneField()的含义：通过User字段声明UserProfile类与User类之间的关系是一对一的
    # 出生日期
    birth = models.DateField(blank=True, null=True)
    # 电话号码
    phone = models.CharField(max_length=20, null=True)

    def __str__(self):
        return 'user {}'.format(self.user.username)


# 个人信息相关的数据
class UserInfo(models.Model):
    user = models.OneToOneField(User, unique=True)
    school = models.CharField(max_length=100, blank=True)
    company = models.CharField(max_length=100, blank=True)
    profession = models.CharField(max_length=100, blank=True)
    address = models.CharField(max_length=100, blank=True)
    aboutme = models.TextField(blank=True)
    photo = models.ImageField(blank=True)

    def __str__(self):
        return "user:{}".format(self.user.username)
